package cn.com.selfsoft.smartcity.core.service;

import cn.com.self.apis.portal.util.ICustomPage;
import cn.com.selfsoft.smartcity.commons.exception.EntityNotFoundException;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * @param <T>
 * @param <K>
 * @param <R>
 *
 */
public interface GenericService<T, K extends Serializable, R> {

    /**
     * @param entity
     * @return
     */
    long count(T entity);

    /**
     * @param parameterMap
     * @return
     */
    long count(Map<String, Object> parameterMap);

    /**
     * @param entity
     * @param page
     * @return
     */
    Page<R> page(T entity, Pageable page);

    /**
     * @param parameterMap
     * @param page
     * @return
     */
    ICustomPage<R> page(Map<String, Object> parameterMap, Pageable page);

    /**
     * @param entity
     * @param sort
     * @return
     */
    List<R> list(T entity, Sort sort);

    /**
     * @param parameterMap
     * @param sort
     * @return
     */
    List<R> list(Map<String, Object> parameterMap, Sort sort);

    /**
     * @param id
     * @return
     */
    R load(K id);

    /**
     * @param entity
     * @return
     */
    R load(T entity);

    /**
     * @param id
     * @throws EntityNotFoundException if the entity is not found.
     */
    void delete(K id) throws EntityNotFoundException;

    /**
     * @param entity
     * @throws EntityNotFoundException if the entity is not found.
     */
    void delete(T entity) throws EntityNotFoundException;

    /**
     * @param entity
     * @param ignoreProperties
     * @return
     */
    R create(T entity, String... ignoreProperties);

    /**
     * @param entity
     * @param ignoreProperties
     * @return
     * @throws EntityNotFoundException if the entity is not found.
     */
    R update(T entity, String... ignoreProperties) throws EntityNotFoundException;

}
